<!-- 地址管理 -->
<template>
  <div class="address-main">
    <Navbar :title="title" />
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import Navbar from "@/components/Navbar";
import Vue from "vue";
import { AddressList, Toast } from "vant";
import addressApi from "@/api/address";

Vue.use(AddressList).use(Toast);
export default {
  name: "address",
  components: {
    Navbar,
  },
  data() {
    return {
      title: "地址管理",
      chosenAddressId: "1",
      addressList: [],
      list: [],
    };
  },
  created() {
    this.getaddressLit();
  },
  methods: {
    //添加地址
    onAdd() {
      this.$router.push({ name: "addressDetail" });
    },
    // 编辑地址
    onEdit(item) {
      var id = item.id;
      console.log(id);
      this.$router.push({ name: "addressInfoDetail", params: { id } });
    },
    getaddressLit() {
      addressApi
        .addressList({
          openId: "15845697415",
        })
        .then((res) => {
          res.data.forEach((item) => {
            this.list.push({
              id: item.id,
              name: item.name,
              tel: item.mobile,
              address: item.address + item.address_detail,
              isDefault: item.is_default,
            });
          });
        });
    },
    bindRegionChange(e){
      console.log(e);
      console.log(111);

    }
  },
};
</script>
<style lang='scss' scoped>
</style>